<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.drugqualityspecSeeStd"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
                            
     <section class="content-header">
        <h1>医院采购情况</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
                <li><a href="#">统计与查询</a></li>
                <li><a href="#">医院采购情况</a></li>
        </ol>
    </section>
        
    <section class="content">
      	<div class="box box-success">
    		<div class="box-header with-border">
    			<h3 class="box-title" id="chartTitle"><c:out value="${lastSea }"></c:out>药品采购金额前十名</h3>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                </div>
            </div>
            <div class="box-body mchart">
                <div id="mChart" style="height: 400px; width:98%; padding: 8px;"></div>
            </div>
        </div>
        <div class=" box box-success">
            <div class="box-body">
             <form  id="form" method="post">
                <div class="input">
                      <div class="textalign">季度<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                    		<table style="width:100%">
                    			<tr>
                    				<td style="width:50%">
                    					<input type="text" name="starttime" id="start" onclick="WdatePicker({dateFmt:'yyyy年M季度', isQuarter:true, isShowOK:false,disabledDates:['....-0[5-9]-..','....-1[0-2]-..'], startDate:'%y-01-01' })" class="textinput" readonly  placeholder="开始季度"/>
                    				</td>
                    				<td>&nbsp;-&nbsp;</td>
                    				<td style="width:50%">
                    					<input type="text" name="endtime" onclick="WdatePicker({dateFmt:'yyyy年M季度', isQuarter:true, isShowOK:false,disabledDates:['....-0[5-9]-..','....-1[0-2]-..'], startDate:'%y-01-01' })" class="textinput" readonly  placeholder="结束季度"/>
                    				</td>
                    			</tr>
                    		</table>
                    </div>
                	<div class="textalign">医疗机构名称<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="hospName" name="hospName" placeholder="医疗机构名称/<spring:message code="message.listForm.pinYinMa"/>" maxlength="100"  /> 
                    </div>
                      <div class="textalign" >
                         <button id="selectSpec" type="button" onclick="search();" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                      <div class="textalign1" >
                         <button type="button" onclick="exportExcel();" class="btn btn-success btn-sm">导 出</button>
                    </div>
                </div>
            </form>
            </div>
          </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
			<button type="button" onclick="toYearAnaByHosp();" class="btn btn-primary btn-sm">按年汇总</button>
			<button type="button" onclick="toMonthAnaByHosp();" class="btn btn-primary btn-sm">按月汇总</button>
        </div>
    </section>
      <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
	var obj ={
 			"names": ['操作',
 	 	             '季度',
	                 '医疗机构名称',
	                 '医疗机构分类',
	                 '采购总金额(万)',
                     '西药采购金额(万)', 
                   	 '中药采购金额(万)',
                     '中药采购率',
                   	 '配送金额(万)',
                     '配送率',
                   	 '入库金额(万)',
					 '入库率'
	                 ],
	        "model": [{ name: 'operate', width: 40, align:"center", sortable: false,
		  				 	formatter: function (val, opts, row) {
		   				 	  return "<a href='javascript:void(0)' onclick='toAnaHospdruginfoTotalSea(\""+row.hosp_code+"\",\""+row.hosp_name+"\",\""+row.date+"\");'  style='background:url(/medstgmini/lib/img/icon/icon.png) no-repeat -40px -80px' class='opIcon' title='药品采购详情'></a>";
		   				 	}
		   				 },
		   	             { name: 'date', width: 100, align:"center", sortable: false},
		                 { name: 'hosp_name', width: 200, align:"center", sortable: false},
		                 { name: 'hosp_classify', width: 80, align:"center", sortable: false},
		                 { name: 'total_amount', width: 80, align:"center", sortable: false},
	                     { name: 'western_amount', width: 80, align:"center", sortable: false},
	                     { name: 'eastern_amount', width: 80, align:"center", sortable: false},
	                     { name: 'eastern_ratio', width: 80, align:"center", sortable: false},
	                     { name: 'del_amount', width: 80, align:"center", sortable: false},
	                     { name: 'del_ratio', width: 80, align:"center", sortable: false},
	                     { name: 'recp_amount', width: 80, align:"center", sortable: false},
	                     { name: 'recp_ratio', width: 80, align:"center", sortable: false}]       
 		};
        $(function () {
        	$('#form :input').bind('keydown', function(event) {if (event.keyCode == "13") {search();}});
            $("#gridlist").jqGrid({
                url: "${ctx}/anaDruginfo/getSeaAnaByHosp.html",
                postData:{starttime:"${date}",endtime:"${date}"},
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 310,
                colNames: obj.names,
                colModel: obj.model,
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: false, 
                viewrecords: true,
                caption: "医院列表",
                gridComplete:function(){
                    autoRNWidth("gridlist");
                },
                jsonReader: {
                	 repeatitems: false,
                    id: "qualitySpecId"
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                	  if($("#mChart").html().length>0){return;}
                	option = {
                		    tooltip : {
                		        trigger: 'axis',
                		        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                		            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                		        }
                		    },
                		    legend: {
                		        data:[]
                		    },
                		    toolbox: {
                		        show : true,
                		        feature : {
                		            mark : {show: false},
                		            dataView : {show: false, readOnly: false},
                		            magicType : {show: false, type: ['line', 'bar', 'stack', 'tiled']},
                		            restore : {show: false},
                		            saveAsImage : {show: false}
                		        }
                		    },
                		    calculable : true,
                		    xAxis : [
                		        {
                		            type : 'value',
                		            name : '采购总金额(万)'
                		        }
                		    ],
                		    yAxis : [
                		        {
                		            type : 'category',
                		            data :  eval(data.conditions.yTime)
                		        }
                		    ],
                		    series : [
                		        {
                		        	barGap:30, 
                		            name:'采购总金额(万)',
                		            type:'bar',
                		            data:eval(data.conditions.total)
                		        }
                		    ]
                		};
                	var myChart = echarts.init(document.getElementById('mChart'));
                    myChart.setOption(option);
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        function search(page) {
        	var start = $("#start").val();
			if(start.length > 0) {
				$("#chartTitle").text(start.replace("年","年第")+"药品采购金额前十名");
			}else {
				$("#chartTitle").text("<c:out value="${lastSea }"></c:out>药品采购金额前十名");
			}
			
            var data =formatForm("form");
            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:data,
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入
        }
        
        function toYearAnaByHosp(){
        	window.location.href="${ctx}/anaDruginfo/toYearAnaByHosp.html"; 
        }
        
        function toAnaByHosp(){
        	window.location.href="${ctx}/anaDruginfo/toAnaByHosp.html"; 
        }
        
        function toMonthAnaByHosp(){
        	window.location.href="${ctx}/anaDruginfo/toMonthAnaByHosp.html"; 
        }
        function toAnaHospdruginfoTotalSea(hospCode,hospName,date){
        	var postData = {hospCode:hospCode,hospName:hospName,date:date};
        	$.StandardPost("${ctx}/anaDruginfo/toAnaHospdruginfoTotalSea.html",postData);
        }
        function exportExcel(){
        	$("#form").attr("action","${ctx}/anaDruginfo/exportExcelHospWithSea.html?"+gridParam("#gridlist"))
            .submit();
        }
        var objTemp = null;
        function gridParam(gridlist){
        	if(!objTemp){
        		objTemp = $.extend(true, {}, obj);
        	}
        	var namesTemp = objTemp.names;
        	var modelTemp = objTemp.model;
			if($.inArray('操作',namesTemp) >= 0) {
				namesTemp.splice($.inArray('操作',namesTemp),1);
				modelTemp.splice(0,1);
			}
			var colModelStr =""; 
        	for(var mod in modelTemp){
        		colModelStr+=modelTemp[mod].name+",";
        	}
        	
        	return "colNames="+namesTemp.toString()+"&colModel="+colModelStr.substring(0,colModelStr.length-1);			
		}
    </script>
</body>
</html> 
                          
                  
                  